unit fTambah;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ZAbstractTable, ZDataset, DB, ZAbstractRODataset, ZAbstractDataset,
  ZConnection, ComCtrls, StdCtrls, Setting, Grids, ExtCtrls;

type
  TPenyimpan = record
     ID:String;
     NAMA:String;
  end;
  TTPenyimpan = array of TPenyimpan;
  TDpt = record
     KODE:String;
     NAMA:String;
  end;
  TTDpt = array of TDpt;
  TForm_Ftambah = class(TForm)
    Button1: TButton;
    GroupBox1: TGroupBox;
    Label6: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label18: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label24: TLabel;
    Label28: TLabel;
    Label30: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label36: TLabel;
    TextNIK: TEdit;
    TextKK: TEdit;
    TextNama: TEdit;
    TextTempat: TEdit;
    TextAlamat: TEdit;
    TextRW: TEdit;
    TextRT: TEdit;
    TextKeterangan: TEdit;
    cbKabkot: TComboBox;
    cbKec: TComboBox;
    cbDesa: TComboBox;
    cbJk: TComboBox;
    cbKawin: TComboBox;
    ZConnection1: TZConnection;
    ZQuery1: TZQuery;
    ZTable1: TZTable;
    txtDusun: TEdit;
    Label26: TLabel;
    Label37: TLabel;
    txtUsia: TEdit;
    cbTgl: TComboBox;
    cbBulan: TComboBox;
    txtTahun: TEdit;
    GroupBox3: TGroupBox;
    Label2: TLabel;
    ZTable2: TZTable;
    Label4: TLabel;
    cbPemilih: TComboBox;
    cbCacat: TComboBox;
    btnBatal: TButton;
    Label7: TLabel;
    cbPend: TComboBox;
    cbPek: TComboBox;
    Label8: TLabel;
    cbStatR: TComboBox;
    Label10: TLabel;
    cbWN: TComboBox;
    Label11: TLabel;
    GroupBox4: TGroupBox;
    cbT1: TComboBox;
    cbT2: TComboBox;
    cbT3: TComboBox;
    cbT4: TComboBox;
    Label14: TLabel;
    Label17: TLabel;
    Label19: TLabel;
    Label22: TLabel;
    Label13: TLabel;
    Timer1: TTimer;
    Label1: TLabel;
    cbAgama: TComboBox;
    Button2: TButton;
    ZQuery2: TZQuery;
    qryCek: TZQuery;
    textIbu: TEdit;
    Label23: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure HitungUsia(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure TextNIKKeyPress(Sender: TObject; var Key: Char);
    procedure TextNamaKeyPress(Sender: TObject; var Key: Char);
    procedure cbKabkotChange(Sender: TObject);
    procedure cbKecChange(Sender: TObject);
    procedure cbDesaChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnTPSClick(Sender: TObject);
    procedure btnBatalClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure cbT1Change(Sender: TObject);
    procedure cbT2Change(Sender: TObject);
    procedure cbT3Change(Sender: TObject);
    procedure cbT4Change(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure txtTahunKeyPress(Sender: TObject; var Key: Char);
    procedure txtTahunKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure txtTahunChange(Sender: TObject);
    procedure txtTahunClick(Sender: TObject);
    procedure txtTahunExit(Sender: TObject);
    function hitung: integer;
    function HandleSpec(Asal: String):String;
  private
    function cekForm: Boolean;
    procedure KeyOnlyNum(Sender: TObject; var Key: Char);
    function getTgl: String;
    procedure AutoSizeCol(Grid: TStringGrid; Column: integer);
    procedure BukanGanda;
    procedure HapusPemilih;
    procedure HapusTanda;
    procedure PindahAlamat;
    procedure UbahTanda(td : String);
    function getDesa(kode: String): String;
    function getIdsimpan(tabel: String): String;
    function getIduser(id: String): String;
    function getKabkot(kode: String): String;
    function getKec(kode: String): String;
    function getSimpan(id: String): String;
    function getTabel(id: String): String;
    function ketAP(id: integer): String;
    function ketCa(id: integer): String;
    function ketGanda(id: integer): String;
    function ketPek(id: integer): String;
    function ketPend(id: integer): String;
    function ketS1(id: integer): String;
    function ketS2(id: integer): String;
    function ketSP(id: integer): String;
    function ketSR(id: integer): String;
    function ketTPS(id: String): String;
    function ketWN(id: integer): String;
    { Private declarations }
  public
    { Public declarations }
    //constructor Create(AOwner: TComponent; tabel: String; IDT:String);             overload;
    constructor Create(AOwner: TComponent; kode:String; kota:String=''; kec:String=''; desa:String='';proses:integer=0;user:string='');             overload;
  end;

var
  proses_sekarang: integer;
  Form_Ftambah: TForm_Ftambah;
  bPenyimpan:TTPenyimpan;
  bDesa:TTDpt;
  bKec:TTDpt;
  bKabkot:TTDpt;
  ptabel,ptabelx,pid,pidx,tid,tidx:String;
  atb:Integer;
  ganda:Boolean;
  ikabkot:String;
  ikec:String;
  idesa:String;
  sKabkot,sKabkot2,skodekab,skodekec: String;
  sKec,sKec2: String;
  sDesa,sDesa2,idTPS,idTPS2: String;
  username:String;

implementation
{$R *.dfm}
procedure TForm_Ftambah.cbDesaChange(Sender: TObject);
var
  pilihan: String;
begin
  pilihan := cbDesa.Items[cbDesa.ItemIndex];
  with ZTable1 do
  begin
    Active := False;
    TableName := 'desa';
    Filter := 'TAMPIL = ' + QuotedStr(pilihan) + ' and KODE_KECAMATAN = ' +
      QuotedStr(sKec);
    Filtered := True;
    Active := True;
    First;
    sDesa := FieldByName('KODE_DESA').AsString;
  end;
end;

procedure TForm_Ftambah.cbKabkotChange(Sender: TObject);
var
  pilihan: String;
begin
  pilihan := cbKabkot.Items[cbKabkot.ItemIndex];
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kabkot';
    Filter := 'TAMPIL = ' + QuotedStr(pilihan);
    Filtered := True;
    Active := True;
    First;
    sKabkot := FieldByName('KODE').AsString;
    // cb2
    Active := False;
    TableName := 'kecamatan';
    Filter := 'KODE_KABKOT = ' + QuotedStr(sKabkot);
    Filtered := True;
    Active := True;
    First;
  end;
  cbKec.Clear;
  cbDesa.Clear;
  while (not ZTable1.Eof) do
  begin
    cbKec.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    ZTable1.Next;
  end;
end;

procedure TForm_Ftambah.cbKecChange(Sender: TObject);
var
  pilihan: String;
begin
  pilihan := cbKec.Items[cbKec.ItemIndex];
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kecamatan';
    Filter := 'TAMPIL = ' + QuotedStr(pilihan) + ' and KODE_KABKOT = ' + QuotedStr
      (sKabkot);
    Filtered := True;
    Active := True;
    First;
    sKec := FieldByName('KODE_KECAMATAN').AsString;
    // cb2
    Active := False;
    TableName := 'desa';
    Filter := 'KODE_KECAMATAN = ' + QuotedStr(sKec);
    Filtered := True;
    Active := True;
    First;
  end;
  cbDesa.Clear;
  while (not ZTable1.Eof) do
  begin
    cbDesa.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    ZTable1.Next;
  end;
end;

procedure TForm_Ftambah.cbT1Change(Sender: TObject);
var
  pilihan: String;
begin
  pilihan := cbT1.Items[cbT1.ItemIndex];
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kabkot';
    Filter := 'TAMPIL = ' + QuotedStr(pilihan);
    Filtered := True;
    Active := True;
    First;
    skabkot2 := FieldByName('KODE').AsString;
    // cb2
    Active := False;
    TableName := 'kecamatan';
    Filter := 'KODE_KABKOT = ' + QuotedStr(skabkot2);
    Filtered := True;
    Active := True;
    First;
  end;
  cbT2.Clear;
  cbT3.Clear;
  cbT4.Clear;
  while (not ZTable1.Eof) do
  begin
    cbT2.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    ZTable1.Next;
  end;
  idtps:='0';
end;

procedure TForm_Ftambah.cbT2Change(Sender: TObject);
var
  pilihan: String;
begin
  pilihan := cbT2.Items[cbT2.ItemIndex];
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kecamatan';
    Filter := 'TAMPIL = ' + QuotedStr(pilihan) + ' and KODE_KABKOT = ' + QuotedStr
      (sKabkot2);
    Filtered := True;
    Active := True;
    First;
    sKec2 := FieldByName('KODE_KECAMATAN').AsString;
    // cb2
    Active := False;
    TableName := 'desa';
    Filter := 'KODE_KECAMATAN = ' + QuotedStr(sKec2);
    Filtered := True;
    Active := True;
    First;
  end;
  cbT3.Clear;
  cbT4.Clear;
  while (not ZTable1.Eof) do
  begin
    cbT3.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    ZTable1.Next;
  end;
  idtps:='0';
end;

procedure TForm_Ftambah.cbT3Change(Sender: TObject);
var
  pilihan: String;
begin
  pilihan := cbT3.Items[cbT3.ItemIndex];
  with ZTable1 do
  begin
    Active := False;
    TableName := 'desa';
    Filter := 'TAMPIL = ' + QuotedStr(pilihan) + ' and KODE_KECAMATAN = ' +
      QuotedStr(sKec2);
    Filtered := True;
    Active := True;
    First;
    sDesa2 := FieldByName('KODE_DESA').AsString;
    //
    Active := False;
    TableName := 'daftar_tps';
    Filter := 'KODE_DESA='+QuotedStr(sdesa2);
    Filtered:=True;
    Active := True;
    First;
  end;
  cbT4.Clear;
  while (not ZTable1.Eof) do
  begin
    cbT4.Items.Add(ZTable1.FieldByName('NAMA').AsString);
    ZTable1.Next;
  end;
  idtps:='0';
end;

procedure TForm_Ftambah.cbT4Change(Sender: TObject);
var
  pilihan: String;
begin
  pilihan := cbT4.Items[cbT4.ItemIndex];
  with ZTable1 do
  begin
    Active := False;
    TableName := 'daftar_tps';
    Filter := 'NAMA = ' + QuotedStr(pilihan) + ' and KODE_DESA = ' +
      QuotedStr(sDesa2);
    Filtered := True;
    Active := True;
    First;
    idTPS := FieldByName('ID_TPS').AsString;
  end;
end;

Function TForm_Ftambah.cekForm() : Boolean;
var
  sTemp:Boolean;
begin
  sTemp:=False;
  if ((TextNIK.Text<>'') and (TextNama.Text<>'') and (TextRW.Text<>'') and (TextRT.Text<>'') and (cbKabkot.ItemIndex>-1) and (cbKec.ItemIndex>-1) and (cbDesa.ItemIndex>-1) and (cbJk.ItemIndex>-1) and (cbKawin.ItemIndex>-1)) then begin
    if (txtUsia.Text<>'') then   begin
//    showMessage('bbb');
      sTemp:=True
      end
    else if ((cbTgl.ItemIndex>0) and (cbBulan.ItemIndex>0) and (txtTahun.Text<>'')) then
//    showMessage('ccc');
      sTemp:=True
  end;
  Result := sTemp;
end;

Function cekRTRW(kata:String) : String;
var
  stemp:String;
begin
  sTemp:='';
  if (Length(kata)=1) then
    sTemp:='00'+kata
  else if (Length(kata)=2) then
    sTemp:='0'+kata
  else if (Length(kata)>3) then
    sTemp:=Copy(kata, Length(kata)-3, 3)
  else
    sTemp:=kata;
  Result := sTemp;
end;

Function TForm_Ftambah.getTgl() : String;
var
  sTemp,tgl,bln,thn:String;
  selisih:integer;
begin
  sTemp:='';
  if ((cbTgl.ItemIndex>0) and (cbBulan.ItemIndex>0) and (txtTahun.Text<>'')) then begin
    tgl:=cbTgl.Items[cbTgl.ItemIndex];
    if(Length(tgl) = 1) then
      tgl := '0'+tgl;
    bln:=cbBulan.Items[cbBulan.ItemIndex];
    if(Length(bln) = 1) then
      bln := '0'+bln;
    thn:=txtTahun.Text;
    if(Length(thn) = 2) then
    begin
      thn:= '19'+thn;
    end;
    sTemp:=tgl+'-'+bln+'-'+thn;
  end;
  Result := sTemp;
end;

function TForm_FTambah.HandleSpec(Asal: String):String;
var
  temp:string;
begin
  temp := StringReplace(asal, '''', '',[rfReplaceAll, rfIgnoreCase]);
  temp := StringReplace(temp, '\', '',[rfReplaceAll, rfIgnoreCase]);
  result := temp;
end;

procedure TForm_Ftambah.Button1Click(Sender: TObject);
var
  values: TStringList;
  que,tanggal,idtgl, query:String;
  buttonSelected, dobel : Integer;
  bob:Boolean;
  status1:string;
  idtabel,idorang:String;
  message: String;
  usiaSekarang: integer;
  tgllahir : String;
begin
  tgllahir := getTgl;
  usiaSekarang:= hitung;
  if proses_sekarang = 8 then
    status1 := '1'
  else if proses_sekarang = 4 then
    status1 := '3'
  else
    status1 := '0';
    
  dobel := 0;
  //cek NIK dan nama
  with qryCek do
  begin
    Active:=false;
    sql.Clear;
    query:='SELECT ID_USER FROM pemilih_'+sdesa+' WHERE NIK = '+quotedStr(TextNIK.Text)+' AND STATUS2 = ''0'' LIMIT 0,1';
    SQL.Text:=query;
    Active:=true;
    if(recordCount > 0) then
      dobel := 1;
  end;

  with qryCek do
  begin
    Active:=false;
    sql.Clear;
    query:='SELECT ID_USER FROM pemilih_'+sdesa+' WHERE NAMA = '+quotedStr(AnsiUpperCase(TextNama.Text))+' AND TANGGAL = '+quotedStr(tgllahir)+' AND STATUS2 = ''0'' LIMIT 0,1';
    SQL.Text:=query;
    Active:=true;
    if(recordCount > 0) then
      dobel := 2;
  end;

  with qryCek do
  begin
    Active:=false;
    sql.Clear;
    query:='SELECT ID_USER FROM pemilih_'+sdesa+' WHERE NAMA = '+quotedStr(AnsiUpperCase(TextNama.Text))+' AND NIK = '+quotedStr(TextNIK.Text)+' AND TANGGAL = '+quotedStr(tgllahir)+' AND STATUS2 = ''0'' LIMIT 0,1';
    SQL.Text:=query;
    Active:=true;
    if(recordCount > 0) then
      dobel := 3;
  end;

  message := '';
  if ((usiaSekarang < 17) AND (Copy(cbKawin.Items[cbKawin.ItemIndex],1,1) = 'B')) then begin
      showMessage('usia belum 17 tahun dan status belum menikah. Pemilih tidak dapat ditambahkan');
    end
  else begin if dobel = 0 then begin
    message := 'Apakah anda yakin akan menambah data pemilih? Mohon dicek kembali data yang diisikan';
    end
  else
  begin
    case dobel of
    1:
      message := 'Ditemukan data dengan NIK sama: '+TextNIK.Text+' pada database. ';
    2:
      message := 'Ditemukan data dengan NAMA sama: '+AnsiUpperCase(TextNama.Text)+' pada database. ';
    3:
      message := 'Ditemukan data dengan NIK dan NAMA sama pada database. ';
    else message := '';
    end;
    message := message + 'Apakah anda tetap akan menambah data?';
  end;
  //showmessage('test');
  buttonSelected := MessageDlg(message,mtConfirmation , mbOKCancel, 0);
  if buttonSelected = mrOK  then begin

     if (cekForm) then begin
      values := TStringList.Create;
      values.Add('0'); // dummy ID, no meaning
      // NIK`, `NKK`, `NAMA`, `TEMPAT`, `TANGGAL`, '+
      // '`IBU`, `AGAMA`, `KAWIN`, `KELAMIN`, `KELAINAN`, `ALAMAT`, `RW`, `RT`, `KET`, `ID_TANGGAL`
      values.Add(copy(HandleSpec(TextNIK.Text),1,36)); //1
      values.Add(copy(HandleSpec(TextKK.Text),1,36));
      values.Add(copy(AnsiUpperCase(HandleSpec(TextNama.Text)),1,50));
      values.Add(copy(AnsiUpperCase(HandleSpec(TextTempat.Text)),1,36));
      values.Add(getTgl);
      values.Add(copy(AnsiUpperCase(HandleSpec(TextIbu.Text)),1,36));  //6
      values.Add(AnsiUpperCase(cbAgama.Items[cbAgama.ItemIndex]));
      values.Add(AnsiUpperCase(Copy(cbKawin.Items[cbKawin.ItemIndex],1,1)));
      values.Add(AnsiUpperCase(Copy(cbJk.Items[cbJk.ItemIndex],1,1)));
      values.Add(AnsiUpperCase(cbCacat.Items[cbcacat.ItemIndex]));
      values.Add(copy(AnsiUpperCase(HandleSpec(TextAlamat.Text)),1,150));  //11
      values.Add(cbKabkot.Items[cbKabkot.ItemIndex]);
      values.Add(cbKec.Items[cbKec.ItemIndex]);
      values.Add(cbDesa.Items[cbDesa.ItemIndex]);
      values.Add(cekRTRW(TextRW.Text));
      values.Add(cekRTRW(TextRT.Text));                //16
      values.Add(copy(AnsiUpperCase(HandleSpec(txtDusun.Text)),1,30));
      values.Add(copy(AnsiUpperCase(HandleSpec(TextKeterangan.Text)),1,150));
      //tps
      values.Add(idTPS);
      //statusp
      values.Add(IntToStr(cbPemilih.ItemIndex+1));
      //alasanp
//      values.Add(IntToStr(cbPerbaikan.ItemIndex+1));
      //cacat
      values.Add(IntToStr(cbCacat.ItemIndex));           //21
      //pendidikan
      values.Add(IntToStr(cbPend.ItemIndex+1));
      //pekerjaan
      if(cbPek.ItemIndex<=11) then
        values.Add(IntToStr(cbPek.ItemIndex+1))
      else
        values.Add(IntToStr(cbPek.ItemIndex+3));
      //statusr
      values.Add(IntToStr(cbStatR.ItemIndex+1));
      //wn
      values.Add(IntToStr(cbWN.ItemIndex+1));                  //25
      //tanggal
      tanggal := FormatDateTime('yyyy-mm-dd hh:mm:ss', Now());
      with ZQuery1 do  //masukkin nih gan
        begin
          Active:=False;
          sql.Clear;
          sql.Text := 'INSERT INTO tanggal (TANGGAL) VALUES ("'+tanggal+'")';
          ExecSQL;
        end;
      with ZQuery1 do  //masukkin nih gan
        begin
          Active:=False;
          sql.Clear;
          sql.Text := 'SELECT * FROM tanggal ORDER BY ID_TANGGAL DESC';
          Active:=True;
          idtgl := FieldByName('ID_TANGGAL').AsString;  //dapat ID_TGL
        end;
//      ShowMessage('idtgl='+idtgl);
      //query query
      with ZQuery1 do  //masukkin nih gan
          begin
            //pemilih
            Active:=False;
            sql.Clear;
            que := 'CREATE TABLE IF NOT EXISTS pemilih_'+sdesa+'('+
                          'ID_USER int(11) NOT NULL AUTO_INCREMENT,'+
                          'NIK char(36) NOT NULL,'+
                          'NKK char(36) NOT NULL,'+
                          'NAMA char(50) NOT NULL,'+
                          'TEMPAT char(36) NOT NULL,'+
                          'TANGGAL char(10) NOT NULL,'+
                          'IBU char(36) NOT NULL,'+
                          'AGAMA char(36) NOT NULL,'+
                          'KAWIN char(1) NOT NULL,'+
                          'KELAMIN char(1) NOT NULL,'+
                          'KELAINAN char(36) NOT NULL,'+
                          'ALAMAT char(150) NOT NULL,'+
                          'RW char(3) NOT NULL,'+
                          'RT char(3) NOT NULL,'+
                          'DUSUN char(30) NOT NULL,'+
                          'KET char(150) NOT NULL,'+
                          'ID_TANGGAL int(11) NOT NULL,'+
                          'TPS int(11) NOT NULL,'+
                          'STATUS1 char(1) NOT NULL,'+
                          'STATUS2 char(1) NOT NULL,'+
                          'GANDA char(1) NOT NULL,'+
                          'STATUS3 char(1) NOT NULL,'+
                          'STATUSP char(1) NOT NULL,'+
                          'ALASANP char(1) NOT NULL,'+
                          'CACAT char(1) NOT NULL,'+
                          'PENDIDIKAN char(1) NOT NULL,'+
                          'PEKERJAAN char(1) NOT NULL,'+
                          'STATUSR char(1) NOT NULL,'+
                          'WN char(1) NOT NULL,'+
                          'PRIMARY KEY (ID_USER))';
         //   showmessage(que);
            sql.text:=que;
            ExecSQL;
            //penyimpan
            Active:=False;
            sql.Clear;
            //ubah
            sql.Text := 'INSERT IGNORE INTO penyimpan (NAMA,UPLOAD) VALUES ("pemilih_'+sdesa+'",'+QuotedStr('')+')';
            ExecSQL;
          end;
      with zquery1 do begin
          active:=false;
          sql.Clear;
          que:='INSERT INTO pemilih_'+sdesa+' (NIK,NKK,NAMA,TEMPAT,TANGGAL,IBU,AGAMA,KAWIN,KELAMIN,KELAINAN,ALAMAT,RW,RT,DUSUN,KET,ID_TANGGAL,TPS,STATUS1,STATUS2,GANDA,STATUS3,STATUSP,CACAT,PENDIDIKAN,PEKERJAAN,STATUSR,WN) VALUES ('+
            QuotedStr(values[1])+','+
            QuotedStr(values[2])+','+
            QuotedStr(values[3])+','+
            QuotedStr(values[4])+','+
            QuotedStr(values[5])+','+
            QuotedStr(values[6])+','+
            QuotedStr(values[7])+','+
            QuotedStr(values[8])+','+
            QuotedStr(values[9])+','+
            QuotedStr(values[10])+','+
            QuotedStr(values[11])+','+
            QuotedStr(values[15])+','+
            QuotedStr(values[16])+','+
            QuotedStr(values[17])+','+
            QuotedStr(values[18])+','+
            idtgl+','+
            values[19]+','+
            QuotedStr(status1)+','+
            QuotedStr('0')+','+
            QuotedStr('0')+','+
            QuotedStr('0')+','+
            QuotedStr(values[20])+','+
            QuotedStr(values[21])+','+
            QuotedStr(values[22])+','+
            QuotedStr(values[23])+','+
            QuotedStr(values[24])+','+
            QuotedStr(values[25])+')';
//          ShowMessage(que);
          sql.text:=que;
          ExecSQL;
      end;
      with zquery2 do begin
        //ambil id orang yang baru dimasukin
        Active:=false;
        Sql.Clear;
        Sql.Text:='SELECT MAX(ID_USER) AS MAX FROM pemilih_'+sdesa;
        Active:=True;
        idorang := FieldByName('MAX').AsString;
      end;
      with zquery2 do begin
        //ambil id tabelnya yang baru dimasukin
        Active:=false;
        Sql.Clear;
        Sql.Text:='SELECT ID FROM penyimpan WHERE NAMA LIKE '+QuotedStr('pemilih_'+sdesa);
        Active:=True;
        idtabel := FieldByName('ID').AsString;
      end;
      with zquery2 do begin
        //masukin history
        active:=false;
          sql.Clear;
          que:='INSERT INTO history (ID_USER,NIK,NKK,NAMA,TEMPAT,TANGGAL,IBU,AGAMA,KAWIN,KELAMIN,KELAINAN,ALAMAT,RW,RT,DUSUN,KET,ID_TANGGAL,TPS,STATUS1,STATUS2,GANDA,STATUS3,STATUSP,CACAT,PENDIDIKAN,PEKERJAAN,STATUSR,WN,USERNAME,KET_AKSI) VALUES ('+
            QuotedStr(idtabel+'-'+idorang)+','+
            QuotedStr(values[1])+','+
            QuotedStr(values[2])+','+
            QuotedStr(values[3])+','+
            QuotedStr(values[4])+','+
            QuotedStr(values[5])+','+
            QuotedStr(values[6])+','+
            QuotedStr(values[7])+','+
            QuotedStr(values[8])+','+
            QuotedStr(values[9])+','+
            QuotedStr(values[10])+','+
            QuotedStr(values[11])+','+
            QuotedStr(values[15])+','+
            QuotedStr(values[16])+','+
            QuotedStr(values[17])+','+
            QuotedStr(values[18])+','+
            idtgl+','+
            values[19]+','+
            QuotedStr(status1)+','+
            QuotedStr('0')+','+
            QuotedStr('0')+','+
            QuotedStr('0')+','+
            QuotedStr(values[20])+','+
            QuotedStr(values[21])+','+
            QuotedStr(values[22])+','+
            QuotedStr(values[23])+','+
            QuotedStr(values[24])+','+
            QuotedStr(values[25])+','+
            QuotedStr(username)+','+
            QuotedStr('1')+
            ')';
//          ShowMessage(que);
          sql.text:=que;
          ExecSQL;
      end;
      ShowMessage('Data pemilih telah berhasil ditambah.');
      Close;
    end
      else
    ShowMessage('Cek jangan ada yang kosong pada : NIK, Nama Lengkap, Tanggal Lahir / Usia, Alamat (Terutama RT/RW), Status Pernikahan, Jenis Kelamin');
  end;
  end;
end;

procedure TForm_Ftambah.UbahTanda(td : String);
var
  query,idx:String;
  temp:TStrings;
begin
  ZQuery1.Active:=false;
    zquery1.SQL.Clear;
    query:='UPDATE '+ptabel+' SET STATUS2='+QuotedStr(td)+' WHERE ID_USER='+pid;
    zquery1.SQL.text:=query;
    zquery1.ExecSQL;
    //cek data_ganda
    with ZQuery1 do begin
      Active:=false;
      sql.Clear;
      query:='SELECT * FROM data_ganda WHERE ID_USER1='+QuotedStr(tid+'-'+pid)+' OR ID_USER2='+QuotedStr(tid+'-'+pid);
      SQL.Text:=query;
      Active:=true;
    end;
    //kalau cuma sepasang, ubah
    if ZQuery1.RecordCount=1 then begin
      if (ZQuery1.FieldByName('ID_USER1').AsString=tid+'-'+pid) then
        idx:=ZQuery1.FieldByName('ID_USER2').AsString
      else
        idx:=ZQuery1.FieldByName('ID_USER1').AsString;
       with ZQuery1 do begin
        Active:=false;
        sql.Clear;
        query:='UPDATE '+ptabel+' SET GANDA="0" WHERE ID_USER='+pid;
        SQL.Text:=query;
        ExecSQL;
        //
        Active:=false;
        sql.Clear;
        if atb=1 then
          query:='DELETE FROM data_ganda WHERE ID_USER1='+QuotedStr(tid+'-'+pid)+' OR ID_USER2='+QuotedStr(tid+'-'+pid)
        else
          query:='DELETE FROM data_ganda WHERE (ID_USER1='+QuotedStr(tid+'-'+pid)+' AND ID_USER2='+QuotedStr(tidx+'-'+pidx)+') OR (ID_USER1='+QuotedStr(tidx+'-'+pidx)+' AND ID_USER2='+QuotedStr(tid+'-'+pid)+')';
        SQL.Text:=query;
        ExecSQL;
      end;
    end;
    //
    if (idx<>'') then begin
      with ZQuery1 do begin
        Active:=false;
        sql.Clear;
        query:='SELECT * FROM data_ganda WHERE ID_USER1='+QuotedStr(idx)+' OR ID_USER2='+QuotedStr(idx);
        SQL.Text:=query;
        Active:=true;
      end;
      //kalau sudah habis, ubah
      if (ZQuery1.RecordCount<1) and (idx<>'') then begin
         with ZQuery1 do begin
          Active:=false;
          sql.Clear;
          temp := TStringList.Create; //1
          try
            ExtractStrings(['-'], [], PChar(idx), temp);
             tidx := temp[0];
             pidx := temp[1];
          finally
            temp.Free;
          end;
          query:='SELECT * FROM penyimpan WHERE ID='+tidx;
          sql.Text:=query;
          active:=True;
          ptabelx:=FieldByName('NAMA').AsString;
          //
          Active:=false;
          sql.Clear;
          query:='UPDATE '+ptabelx+' SET GANDA="0" WHERE ID_USER='+pidx;
          SQL.Text:=query;
          ExecSQL;
         end;
      end;
    end;
end;

procedure TForm_Ftambah.PindahAlamat;
var
  pidn,tidn:String;
begin
  if (ptabel<>'pemilih_'+sdesa) then begin
      //pindah tabel
      ZQuery1.SQL.Clear;
      ZQuery1.SQL.Add('CREATE TABLE IF NOT EXISTS `'+'pemilih_'+sdesa+'` ('+
      '`ID_USER` int(11) NOT NULL AUTO_INCREMENT,'+
      '`NIK` char(36) NOT NULL,'+
      '`NKK` char(36) NOT NULL,'+
      '`NAMA` char(50) NOT NULL,'+
      '`TEMPAT` char(36) NOT NULL,'+
      '`TANGGAL` char(10) NOT NULL,'+
      '`IBU` char(36) NOT NULL,'+
      '`AGAMA` char(36) NOT NULL,'+
      '`KAWIN` char(1) NOT NULL,'+
      '`KELAMIN` char(1) NOT NULL,'+
      '`KELAINAN` char(36) NOT NULL,'+
      '`ALAMAT` char(150) NOT NULL,'+
      '`RW` char(3) NOT NULL,'+
      '`RT` char(3) NOT NULL,'+
      '`DUSUN` char(30) NOT NULL,'+
      '`KET` char(150) NOT NULL,'+
      '`ID_TANGGAL` int(11) NOT NULL,'+
      'TPS int(11) NOT NULL,'+
      'STATUS1 char(1) NOT NULL,'+
      'STATUS2 char(1) NOT NULL,'+
      'GANDA char(1) NOT NULL,'+
      'PRIMARY KEY (`ID_USER`)'+
      ') ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;');
      ZQuery1.ExecSQL;
      //masukin
      ZQuery1.Active:=False;
      ZQuery1.sql.Clear;
      ZQuery1.sql.Text := 'INSERT IGNORE INTO penyimpan (NAMA) VALUES ("pemilih_'+sdesa+'")';
      ZQuery1.ExecSQL;
    end;
    with ZTable1 do begin
      active:=false;
      TableName:=ptabel;
      Filter:='ID_USER='+QuotedStr(pid);
      Filtered:=true;
      Active:=true;
      First;
    end;
    with zquery1 do begin
        active:=false;
        sql.Clear;
        sql.Text:='INSERT INTO '+'pemilih_'+sdesa+' (NIK,NKK,NAMA,TEMPAT,TANGGAL,IBU,AGAMA,KAWIN,KELAMIN,KELAINAN,ALAMAT,RW,RT,DUSUN,KET,ID_TANGGAL,TPS,STATUS1,STATUS2,GANDA) VALUES ('+
          QuotedStr(ZTable1.FieldByName('NIK').AsString)+','+
          QuotedStr(ZTable1.FieldByName('NKK').AsString)+','+
          QuotedStr(ZTable1.FieldByName('NAMA').AsString)+','+
          QuotedStr(ZTable1.FieldByName('TEMPAT').AsString)+','+
          QuotedStr(ZTable1.FieldByName('TANGGAL').AsString)+','+
          QuotedStr(ZTable1.FieldByName('IBU').AsString)+','+
          QuotedStr(ZTable1.FieldByName('AGAMA').AsString)+','+
          QuotedStr(ZTable1.FieldByName('KAWIN').AsString)+','+
          QuotedStr(ZTable1.FieldByName('KELAMIN').AsString)+','+
          QuotedStr(ZTable1.FieldByName('KELAINAN').AsString)+','+
          QuotedStr(TextAlamat.Text)+','+
          QuotedStr(cekRTRW(TextRW.Text))+','+
          QuotedStr(cekRTRW(textRT.Text))+','+
          QuotedStr(txtDusun.Text)+','+
          QuotedStr(ZTable1.FieldByName('KET').AsString)+','+
          ZTable1.FieldByName('ID_TANGGAL').AsString+','+
          ZTable1.FieldByName('TPS').AsString+','+
          QuotedStr(ZTable1.FieldByName('STATUS1').AsString)+','+
          QuotedStr('4')+','+
          QuotedStr(ZTable1.FieldByName('GANDA').AsString)+')';
        ExecSQL;
    end;
     with ZTable2 do begin
      active:=false;
      TableName:='pemilih_'+sdesa;
      SortedFields:='ID_USER';
      SortType:=stDescending;
      Active:=true;
      First;
      pidn:=FieldByName('ID_USER').AsString;
      SortedFields:='';
      //
      active:=false;
      TableName:='penyimpan';
      Filter:='NAMA='+QuotedStr('pemilih_'+sdesa);
      Filtered:=true;
      Active:=true;
      First;
      tidn:=FieldByName('ID').AsString;
    end;
    with zquery1 do begin
        //masukkin history dah?
        //hapus
        active:=false;
        sql.Clear;
        sql.Text:='DELETE FROM '+ptabel+' WHERE ID_USER='+QuotedStr(pid);
        ExecSQL;
        ShowMessage('Pemilih telah pindah alamat');
    end;
end;

procedure TForm_Ftambah.btnBatalClick(Sender: TObject);
begin
  Close;
end;

procedure TForm_Ftambah.btnTPSClick(Sender: TObject);
var
  kode,tkab,tkec,ttps:String;
  i,idx:Integer;
begin
  with ztable1 do begin
    active:=false;
    TableName:='daftar_tps';
    filter:='ID_TPS='+idtps;
    filtered:=true;
    active:=true;
    first;
  end;
  kode:=ztable1.FieldByName('KODE_DESA').AsString;
  if (kode<>'') then begin
    tkab:=Copy(kode,1,2);
    tkec:=Copy(kode,1,5);
  end
    else
  begin
    tkab:=sDesa;
    tkec:=sKec;
  end;
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kabkot';
    Filtered:=False;
    Active := True;
    First;
  end;
  cbT1.Clear;
  cbT2.Clear;
  cbT3.Clear;
  cbT4.Clear;
  i:=0;
  idx:=-1;
  while (not ZTable1.Eof) do
  begin
    cbT1.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    if (tkab=ZTable1.FieldByName('KODE').AsString) then
      idx:=i;
    ZTable1.Next;
    Inc(i);
  end;
  //ShowMessage(ikabkot);
  cbT1.ItemIndex:=idx;
  if (kode<>'') then begin
    //KEC
    with ZTable1 do
    begin
      Active := False;
      TableName := 'kecamatan';
      Filter := 'KODE_KABKOT='+QuotedStr(tkab);
      Filtered:=True;
      Active := True;
      First;
    end;
    cbT2.Clear;
    i:=0;
    idx:=-1;
    while (not ZTable1.Eof) do
    begin
      cbT2.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
      if (tkec=ZTable1.FieldByName('KODE_KECAMATAN').AsString) then
        idx:=i;
      ZTable1.Next;
      Inc(i);
    end;
    cbT2.ItemIndex:=idx;
    //DESA
    with ZTable1 do
    begin
      Active := False;
      TableName := 'desa';
      Filter := 'KODE_KECAMATAN='+QuotedStr(tkec);
      Filtered:=True;
      Active := True;
      First;
    end;
    cbT3.Clear;
    i:=0;
    idx:=-1;
    while (not ZTable1.Eof) do
    begin
      cbT3.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
      if (kode=ZTable1.FieldByName('KODE_DESA').AsString) and (kode<>'') then
        idx:=i;
      ZTable1.Next;
      Inc(i);
    end;
    cbT3.ItemIndex:=idx;
    //TPS
    with ZTable1 do
    begin
      Active := False;
      TableName := 'daftar_tps';
      Filter := 'KODE_DESA='+QuotedStr(kode);
      Filtered:=True;
      Active := True;
      First;
    end;
    cbT4.Clear;
    i:=0;
    idx:=-1;
    while (not ZTable1.Eof) do
    begin
      cbT4.Items.Add(ZTable1.FieldByName('NAMA').AsString);
      if (idtps=ZTable1.FieldByName('id_tps').AsString) and (kode<>'') then
        idx:=i;
      ZTable1.Next;
      Inc(i);
    end;
    cbT4.ItemIndex:=idx;
  end;
  GroupBox4.Visible:=true;
end;

procedure TForm_Ftambah.BukanGanda;
var
  query,idx:String;
  temp:TStrings;
begin
  with ZQuery1 do begin
      Active:=false;
      sql.Clear;
      query:='SELECT * FROM data_ganda WHERE ID_USER1='+QuotedStr(tid+'-'+pid)+' OR ID_USER2='+QuotedStr(tid+'-'+pid);
      SQL.Text:=query;
      Active:=true;
    end;
    //kalau cuma sepasang, ubah
    if ZQuery1.RecordCount>=1 then begin
      if (ZQuery1.FieldByName('ID_USER1').AsString=tid+'-'+pid) then
        idx:=ZQuery1.FieldByName('ID_USER2').AsString
      else
        idx:=ZQuery1.FieldByName('ID_USER1').AsString;
       with ZQuery1 do begin
        Active:=false;
        sql.Clear;
        query:='UPDATE '+ptabel+' SET GANDA="0" WHERE ID_USER='+pid;
        SQL.Text:=query;
        ExecSQL;
        //
        Active:=false;
        sql.Clear;
        if atb=1 then
          query:='DELETE FROM data_ganda WHERE ID_USER1='+QuotedStr(tid+'-'+pid)+' OR ID_USER2='+QuotedStr(tid+'-'+pid)
        else
          query:='DELETE FROM data_ganda WHERE (ID_USER1='+QuotedStr(tid+'-'+pid)+' AND ID_USER2='+QuotedStr(tidx+'-'+pidx)+') OR (ID_USER1='+QuotedStr(tidx+'-'+pidx)+' AND ID_USER2='+QuotedStr(tid+'-'+pid)+')';
        SQL.Text:=query;
        ExecSQL;
      end;
    end;
    /////
    if (idx<>'') then begin
      with ZQuery1 do begin
        Active:=false;
        sql.Clear;
        query:='SELECT * FROM data_ganda WHERE ID_USER1='+QuotedStr(idx)+' OR ID_USER2='+QuotedStr(idx);
        SQL.Text:=query;
        Active:=true;
      end;
      //kalau sudah habis, ubah
      if (ZQuery1.RecordCount<1) and (idx<>'') then begin
         with ZQuery1 do begin
          Active:=false;
          sql.Clear;
          temp := TStringList.Create; //1
          try
            ExtractStrings(['-'], [], PChar(idx), temp);
             tidx := temp[0];
             pidx := temp[1];
          finally
            temp.Free;
          end;
          query:='SELECT * FROM penyimpan WHERE ID='+tidx;
          sql.Text:=query;
          active:=True;
          ptabelx:=FieldByName('NAMA').AsString;
          //
          Active:=false;
          sql.Clear;
          query:='UPDATE '+ptabelx+' SET GANDA="0" WHERE ID_USER='+pidx;
          SQL.Text:=query;
          ExecSQL;
         end;
      end;
    end;
end;

procedure TForm_Ftambah.HapusTanda;
var
  buttonSelected : Integer;
  que:string;
begin
  buttonSelected := MessageDlg('Apakah anda yakin akan menghilangkan tanda pemilih ini?',mtConfirmation , mbOKCancel, 0);
  if buttonSelected = mrOK  then begin
    with ZQuery1 do begin
      active:=false;
      sql.Clear;
      que:='UPDATE '+ptabel+' SET STATUS2="0" WHERE ID_USER='+pid;
      sql.Text:=que;
      ExecSQL;
    end;
    ShowMessage('Tanda telah dihilangkan');
  end;
end;

procedure TForm_Ftambah.HapusPemilih;
var
  query,idx,ique,itabel:String;
  temp:TStrings;
begin
  with ZQuery1 do begin
      //masukkin history?
      active:=false;
      sql.Clear;
      itabel:=ptabel+'-'+pid;
      query:='UPDATE '+ptabel+' SET STATUS2='+QuotedStr('5')+' WHERE ID_USER='+pid;
//      ShowMessage(query);
      sql.Text:=query;
      ExecSQL;
    end;
    with ZQuery1 do begin
      Active:=false;
      sql.Clear;
      query:='SELECT * FROM data_ganda WHERE ID_USER1='+QuotedStr(tid+'-'+pid)+' OR ID_USER2='+QuotedStr(tid+'-'+pid);
      SQL.Text:=query;
      Active:=true;
    end;
    //kalau cuma sepasang, ubah
    if ZQuery1.RecordCount=1 then begin
      if (ZQuery1.FieldByName('ID_USER1').AsString=tid+'-'+pid) then
        idx:=ZQuery1.FieldByName('ID_USER2').AsString
      else
        idx:=ZQuery1.FieldByName('ID_USER1').AsString;
       with ZQuery1 do begin
        Active:=false;
        sql.Clear;
        query:='UPDATE '+ptabel+' SET GANDA="0" WHERE ID_USER='+pid;
        SQL.Text:=query;
        ExecSQL;
        //
        Active:=false;
        sql.Clear;
        if atb=1 then
          query:='DELETE FROM data_ganda WHERE ID_USER1='+QuotedStr(tid+'-'+pid)+' OR ID_USER2='+QuotedStr(tid+'-'+pid)
        else
          query:='DELETE FROM data_ganda WHERE (ID_USER1='+QuotedStr(tid+'-'+pid)+' AND ID_USER2='+QuotedStr(tidx+'-'+pidx)+') OR (ID_USER1='+QuotedStr(tidx+'-'+pidx)+' AND ID_USER2='+QuotedStr(tid+'-'+pid)+')';
        SQL.Text:=query;
        ExecSQL;
      end;
    end;
    //
    if (idx<>'') then begin
      with ZQuery1 do begin
        Active:=false;
        sql.Clear;
        query:='SELECT * FROM data_ganda WHERE ID_USER1='+QuotedStr(idx)+' OR ID_USER2='+QuotedStr(idx);
        SQL.Text:=query;
        Active:=true;
      end;
      //kalau sudah habis, ubah
      if (ZQuery1.RecordCount<1) and (idx<>'') then begin
         with ZQuery1 do begin
          Active:=false;
          sql.Clear;
          temp := TStringList.Create; //1
          try
            ExtractStrings(['-'], [], PChar(idx), temp);
             tidx := temp[0];
             pidx := temp[1];
          finally
            temp.Free;
          end;
          query:='SELECT * FROM penyimpan WHERE ID='+tidx;
          sql.Text:=query;
          active:=True;
          ptabelx:=FieldByName('NAMA').AsString;
          //
          Active:=false;
          sql.Clear;
          query:='UPDATE '+ptabelx+' SET GANDA="0" WHERE ID_USER='+pidx;
          SQL.Text:=query;
          ExecSQL;
         end;
      end;
    end;
end;

procedure TForm_Ftambah.Button2Click(Sender: TObject);
begin
  idTPS:=idTPS2;
  //
  cbKabkot.Items:=cbT1.Items;
  cbKabkot.ItemIndex:=cbT1.ItemIndex;
  cbKec.Items:=cbT2.Items;
  cbKec.ItemIndex:=cbT2.ItemIndex;
  cbDesa.Items:=cbT3.Items;
  cbDesa.ItemIndex:=cbT3.ItemIndex;
  //txtTPS.Text:=cbT4.Items[cbT4.ItemIndex];
  //
  GroupBox4.Visible:=false;
  GroupBox1.Enabled:=true;
end;

function TForm_Ftambah.Hitung:Integer;
var
  acuan,thn: String;
  hari, bulan, tahun, hari_acuan, bulan_acuan, tahun_acuan, usia: Integer;
  temp: TStrings;
begin
  with ZQuery1 do begin
      Active:=false;
      sql.Clear;
      SQL.Text:='SELECT * FROM info_tanggal WHERE AKTIF = 1';
      Active:=true;
      acuan := formatDateTime('mm/dd/yyyy',fieldByName('TANGGAL').AsDateTime);
    end;
  //showMessage(acuan);
  temp := TStringList.Create;
  try
      ExtractStrings(['/'], [], PChar(acuan), temp);
      if(temp.Count < 3) then begin
        temp := TStringList.Create;
        ExtractStrings(['-'], [], PChar(acuan), temp);
      end;
//      showmessage(temp[1]);
      hari_acuan := StrToInt(temp[1]);
      bulan_acuan := StrToInt(temp[0]);
      tahun_acuan := StrToInt(temp[2]);
    finally
      temp.Free;
    end;
  hari := 0;
  bulan:= 0;
  tahun:= 0;

  if ((cbTgl.ItemIndex>0) and (cbBulan.ItemIndex>0) and (txtTahun.Text<>'')) then begin
    hari:=strtoint(cbTgl.Items[cbTgl.ItemIndex]);
    bulan:=strtoint(cbBulan.Items[cbBulan.ItemIndex]);
    thn:=txtTahun.Text;
    if(Length(thn) = 2) then
    begin
      thn:= '19'+thn;
    end;
    tahun := strtoint(thn);
    usia := tahun_acuan - tahun;
    if(bulan_acuan < bulan) then
      usia := usia - 1
    else if(bulan_acuan = bulan) then begin
      if(hari_acuan < hari) then
        usia:= usia -1;
    end;
    result:= usia;
    //txtUsia.Text:= IntToStr(usia);
  end else result:= 0;
end;

procedure TForm_Ftambah.HitungUsia(Sender: TObject);
var
  acuan,thn: String;
  hari, bulan, tahun, hari_acuan, bulan_acuan, tahun_acuan, usia: Integer;
  temp: TStrings;
begin
  with ZQuery1 do begin
      Active:=false;
      sql.Clear;
      SQL.Text:='SELECT * FROM info_tanggal WHERE AKTIF = 1';
      Active:=true;
      acuan := FormatDateTime('mm/dd/yyyy',fieldByName('TANGGAL').asDateTime);
    end;
  //showMessage(acuan);
  temp := TStringList.Create;
  try
      ExtractStrings(['/'], [], PChar(acuan), temp);
      if(temp.Count < 3) then begin
        temp := TStringList.Create;
        ExtractStrings(['-'], [], PChar(acuan), temp);
      end;
//      showmessage(temp[1]);
      hari_acuan := StrToInt(temp[1]);
      bulan_acuan := StrToInt(temp[0]);
      tahun_acuan := StrToInt(temp[2]);
    finally
      temp.Free;
    end;
  hari := 0;
  bulan:= 0;
  tahun:= 0;

  if ((cbTgl.ItemIndex>0) and (cbBulan.ItemIndex>0) and (txtTahun.Text<>'')) then begin
    hari:=strtoint(cbTgl.Items[cbTgl.ItemIndex]);
    bulan:=strtoint(cbBulan.Items[cbBulan.ItemIndex]);
    thn:=txtTahun.Text;
    if(Length(thn) = 2) then
    begin
      thn:= '19'+thn;
    end;
    tahun := strtoint(thn);
    usia := tahun_acuan - tahun;
    if(bulan_acuan < bulan) then
      usia := usia - 1
    else if(bulan_acuan = bulan) then begin
      if(hari_acuan < hari) then
        usia:= usia -1;
    end;
    txtUsia.Text:= IntToStr(usia);
  end else
    showMessage('silakan masukkan tanggal lahir dengan lengkap');

end;


procedure TForm_Ftambah.Button3Click(Sender: TObject);
begin
  GroupBox4.Visible:=false;
  GroupBox1.Enabled:=true;
end;

constructor TForm_Ftambah.Create(AOwner: TComponent; kode:String; kota:String=''; kec:String=''; desa:String=''; proses:integer=0;user:String='');
begin
    proses_sekarang:=proses;
    if(length(kode)>2)then
    begin
      skodekab:=copy(kode,1,2);
      skodekec:=kode;
    end
    else
    begin
      skodekab:=kode;
      skodekec:='';
    end;
    //skode:=kode;
    skabkot:=kota;
    skec:=kec;
    sdesa:=desa;
    inherited Create(AOwner);
    username := user;
end;

procedure TForm_Ftambah.KeyOnlyNum(Sender: TObject; var Key: Char);
begin
  if not(Key in [#8, '0' .. '9']) then
  begin
    Key := #0;
  end;
end;

procedure TForm_Ftambah.TextNamaKeyPress(Sender: TObject; var Key: Char);
begin
  if not(Key in [#8, #32, #44 .. #46, #65 .. #90, #97 .. #122, '0' .. '9']) then
  begin
    Key := #0;
  end;
end;

procedure TForm_Ftambah.TextNIKKeyPress(Sender: TObject; var Key: Char);
begin
  KeyOnlyNum(Sender, Key);
end;

procedure TForm_Ftambah.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TForm_Ftambah.FormCreate(Sender: TObject);
var
  idx,i,crow:Integer;
  sTgl:TStrings;
  tgl,d,m,y,que:String;
  tblname,kkota,kkec,kdesa:String;
  setting:TSetting_Form;
begin
  setting:=TSetting_Form.Create;
  ZConnection1.HostName:=setting.host;
  ZConnection1.Protocol:=setting.protocol;
  ZConnection1.Database:=setting.database;
  ZConnection1.User:=setting.user;
  ZConnection1.Password:=setting.password;
  ZConnection1.Connected:=true;
  ztable1.Connection:=ZConnection1;
  ztable2.Connection:=ZConnection1;
  ZQuery1.Connection:=ZConnection1;
  ZQuery2.Connection:=ZConnection1;
  qryCek.Connection:=ZConnection1;
  BorderIcons := BorderIcons - [biMaximize];
  //dummy
  {ptabel:='pemilih_09110005';
  pid:='3';}
  WindowState:=wsNormal;
  ikabkot:=Copy(ptabel,9,2);
  ikec:=Copy(ptabel,9,5);
  idesa:=Copy(ptabel,9,8);
  //TABEL-TABEL
  with ZTable1 do begin
    Active:=False;
    TableName:='penyimpan';
    Active:=True;
    SetLength(bPenyimpan,RecordCount);
    I:=0;
    while (not Eof) do begin
      bPenyimpan[I].ID:=FieldByName('ID').AsString;
      bPenyimpan[I].NAMA:=FieldByName('NAMA').AsString;
      Inc(I);
      Next;
    end;
  end;
  //desa
  with ZTable1 do begin
    Active:=False;
    TableName:='desa';
    Active:=True;
    SetLength(bDesa,RecordCount);
    I:=0;
    while (not Eof) do begin
      bDesa[I].KODE:=FieldByName('KODE_DESA').AsString;
      bDesa[I].NAMA:=FieldByName('TAMPIL').AsString;
      Inc(I);
      Next;
    end;
  end;
  //kec
  with ZTable1 do begin
    Active:=False;
    TableName:='kecamatan';
    Active:=True;
    SetLength(bKec,RecordCount);
    I:=0;
    while (not Eof) do begin
      bKec[I].KODE:=FieldByName('KODE_KECAMATAN').AsString;
      bKec[I].NAMA:=FieldByName('TAMPIL').AsString;
      Inc(I);
      Next;
    end;
  end;
  //kota
  with ZTable1 do begin
    Active:=False;
    TableName:='kabkot';
    Active:=True;
    SetLength(bKabkot,RecordCount);
    I:=0;
    while (not Eof) do begin
      bKabkot[I].KODE:=FieldByName('KODE').AsString;
      bKabkot[I].NAMA:=FieldByName('TAMPIL').AsString;
      Inc(I);
      Next;
    end;
  end;
  //------------------------------------------------
  with cbAgama do begin
    clear;
    items.add('ISLAM');
    items.add('PROTESTAN');
    items.add('KATHOLIK');
    items.add('HINDU');
    items.add('BUDHA');
    items.add('KHONGHUCU');
    items.add('LAIN-LAIN');
  end;
  with cbKawin do
  begin
    Clear;
    Items.Add('Belum');
    Items.Add('Sudah');
    Items.Add('Pernah');
  end;
  with cbJk do
  begin
    Clear;
    Items.Add('Laki');
    Items.Add('Perempuan');
  end;
  {with ZTable1 do
  begin
    Active:=False;
    TableName:=ptabel;
    Filter:='ID_USER = '+pid;
    Filtered:=True;
    Active:=True;
    First;
  end;
  TextNIK.Text := ZTable1.FieldByName('NIK').AsString;
  TextKK.Text := ZTable1.FieldByName('NKK').AsString;
  TextNama.Text := ZTable1.FieldByName('NAMA').AsString;
  TextTempat.Text := ZTable1.FieldByName('TEMPAT').AsString;}
  cbTgl.Clear;
  cbTgl.items.Add(' ');
  for I := 1 to 31 do
    cbTgl.Items.Add(IntToStr(I));
  cbBulan.Clear;
  cbBulan.items.Add(' ');
  for I := 1 to 12 do
    cbBulan.Items.Add(IntToStr(I)); {
  tgl:=ZTable1.FieldByName('TANGGAL').AsString;
  sTgl := TStringList.Create;
    try
      ExtractStrings(['-'], [], PChar(tgl), sTgl);
      d := sTgl[0];
      m := sTgl[1];
      y := sTgl[2];
    finally
      sTgl.Free;
    end;
//  d:=Copy(tgl,1,2);
//  m:=Copy(tgl,4,2);
//  y:=Copy(tgl,7,4);
  cbTgl.ItemIndex:=StrToInt(d);
  cbBulan.ItemIndex:=StrToInt(m);
  txtTahun.Text:=y;
//  TextIbu.Text := ZTable1.FieldByName('IBU').AsString;
  TextAgama.Text := ZTable1.FieldByName('AGAMA').AsString;
  if (ZTable1.FieldByName('KAWIN').AsString='B') then
    cbKawin.ItemIndex:=0
  else if (ZTable1.FieldByName('KAWIN').AsString='S') then
    cbKawin.ItemIndex:=1
  else
    cbKawin.ItemIndex:=2;
  if (ZTable1.FieldByName('KELAMIN').AsString='L') then
    cbJk.ItemIndex:=0
  else
    cbJk.ItemIndex:=1;
//  TextKelainan.Text := ZTable1.FieldByName('KELAINAN').AsString;
  TextAlamat.Text := ZTable1.FieldByName('ALAMAT').AsString;
  TextRW.Text := ZTable1.FieldByName('RW').AsString;
  TextRT.Text := ZTable1.FieldByName('RT').AsString;
  TextKeterangan.Text := ZTable1.FieldByName('KET').AsString;
  txtDusun.Text := ZTable1.FieldByName('DUSUN').AsString;
  //TPS
  txtTPS.Enabled:=false;
  with ZTable2 do begin
    active:=false;
    TableName:='daftar_tps';
    filter:='ID_TPS='+IntToStr(ZTable1.FieldByName('TPS').AsInteger);
    idtps:=ZTable1.FieldByName('TPS').AsString;
    filtered:=true;
    active:=true;
    first;
  end;
  txtTPS.Text:=ZTable2.FieldByName('NAMA').AsString;}
  //STATUSP
  with cbPemilih do
  begin
    Clear;
    Items.Add('Biasa');
    //Items.Add('Cacat Mental/Jiwa');
    //Items.Add('Dicabut Hak Pilih');
    //Items.Add('Pidana 5 Tahun');
    //Items.Add('Tidak Punya Hak Pilih');
    //Items.Add('Belum Punya Hak Pilih');
  end;
{  case ZTable1.FieldByName('STATUSP').AsInteger of
    1 : cbPemilih.ItemIndex:=0;
    2 : cbPemilih.ItemIndex:=1;
    3 : cbPemilih.ItemIndex:=2;
    4 : cbPemilih.ItemIndex:=3;
    5 : cbPemilih.ItemIndex:=4;
    6 : cbPemilih.ItemIndex:=5;
    else
  end;}
  //ALASANP
  {cbPerbaikan.Clear;
  cbPerbaikan.Items.Add('Meninggal Dunia'); //ini
  cbPerbaikan.Items.Add('Pindah domisili'); //ini
  cbPerbaikan.Items.Add('Tidak dikenal'); //ini
  cbPerbaikan.Items.Add('Salah status pemilih');
  cbPerbaikan.Items.Add('Salah jenis kelamin');
  cbPerbaikan.Items.Add('Salah nama');
  cbPerbaikan.Items.Add('Salah alamat');
  cbPerbaikan.Items.Add('Terdaftar ganda'); //ini
  cbPerbaikan.Items.Add('Lainnya');
  cbPerbaikan.Items.Add('Dicabut Hak Pilih'); //ini
  cbPerbaikan.Items.Add('Bukan Data Ganda'); //ini
  cbPerbaikan.Items.Add('Hapus Tanda'); //ini
  cbPerbaikan.Items.Add('Hapus Pemilih'); //ini}
  //CACAT
  with cbCacat do
  begin
    Clear;
    Items.Add('Tanpa Cacat');
    Items.Add('Cacat Fisik');
    Items.Add('Cacat Netra/buta');
    Items.Add('Cacat rungu wicara');
    Items.Add('Cacat mental jiwa');
    Items.Add('Cacat fisik/mental');
    Items.Add('Cacat lannya');
  end;
{  case ZTable1.FieldByName('CACAT').AsInteger of
    1 : cbCacat.ItemIndex:=0;
    2 : cbCacat.ItemIndex:=1;
    3 : cbCacat.ItemIndex:=2;
    4 : cbCacat.ItemIndex:=3;
    5 : cbCacat.ItemIndex:=4;
    6 : cbCacat.ItemIndex:=5;
    else
  end;}
  //PENDIDIKAN
  with cbPend do
  begin
    Clear;
    Items.Add('Tidak/Belum Sekolah');
    Items.Add('Tamat SD');
    Items.Add('Tidak Tamat SD');
    Items.Add('SLTP');
    Items.Add('SLTA');
    Items.Add('DI/II');
    Items.Add('DIII');
    Items.Add('S1/D4');
    Items.Add('S2');
    Items.Add('S3');
  end;
{  case ZTable1.FieldByName('PENDIDIKAN').AsInteger of
    1 : cbPend.ItemIndex:=0;
    2 : cbPend.ItemIndex:=1;
    3 : cbPend.ItemIndex:=2;
    4 : cbPend.ItemIndex:=3;
    5 : cbPend.ItemIndex:=4;
    6 : cbPend.ItemIndex:=5;
    7 : cbPend.ItemIndex:=6;
    8 : cbPend.ItemIndex:=7;
    9 : cbPend.ItemIndex:=8;
    10 : cbPend.ItemIndex:=9;
    else
  end;}
  //PEKERJAAN
  with cbPek do
  begin
    Clear;
    Items.Add('Pelajar');
    Items.Add('Pengurus RT');
    Items.Add('Pensiunan');
    Items.Add('Blm/tdk bekerja');
    Items.Add('Petani');
    Items.Add('Peternak');
    Items.Add('Nelayan');
    Items.Add('Industri');
    Items.Add('Kontruksi');
    Items.Add('Perdagangan');
    Items.Add('Transportasi');
    Items.Add('PNS');
    //Items.Add('TNI');
    //Items.Add('Polri');
    Items.Add('Pensiunan TNI/Polri');
    Items.Add('Jasa lainnya');
  end;
{  case ZTable1.FieldByName('PEKERJAAN').AsInteger of
    1 : cbPek.ItemIndex:=0;
    2 : cbPek.ItemIndex:=1;
    3 : cbPek.ItemIndex:=2;
    4 : cbPek.ItemIndex:=3;
    5 : cbPek.ItemIndex:=4;
    6 : cbPek.ItemIndex:=5;
    7 : cbPek.ItemIndex:=6;
    8 : cbPek.ItemIndex:=7;
    9 : cbPek.ItemIndex:=8;
    10 : cbPek.ItemIndex:=9;
    11 : cbPek.ItemIndex:=10;
    12 : cbPek.ItemIndex:=11;
    13 : cbPek.ItemIndex:=12;
    14 : cbPek.ItemIndex:=13;
    15 : cbPek.ItemIndex:=14;
    else
  end;}
  //STATUSR
  with cbStatR do
  begin
    Clear;
    Items.Add('Kepala RT');
    Items.Add('Istri/Suami');
    Items.Add('Anak');
    Items.Add('Menantu');
    Items.Add('Cucu');
    Items.Add('Orang Tua');
    Items.Add('Mertua');
    Items.Add('Famili Lain');
    Items.Add('Pembantu');
    Items.Add('Lainnya');
  end;
{  case ZTable1.FieldByName('STATUSR').AsInteger of
    1 : cbStatR.ItemIndex:=0;
    2 : cbStatR.ItemIndex:=1;
    3 : cbStatR.ItemIndex:=2;
    4 : cbStatR.ItemIndex:=3;
    5 : cbStatR.ItemIndex:=4;
    6 : cbStatR.ItemIndex:=5;
    7 : cbStatR.ItemIndex:=6;
    8 : cbStatR.ItemIndex:=7;
    9 : cbStatR.ItemIndex:=8;
    10 : cbStatR.ItemIndex:=9;
    else
  end;}
  //WN
  with cbWN do
  begin
    Clear;
    Items.Add('WNI');
    Items.Add('WNA');
  end;
{  case ZTable1.FieldByName('WN').AsInteger of
    1 : cbWN.ItemIndex:=0;
    2 : cbWN.ItemIndex:=1;
    else
  end; }
  //KOTA
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kabkot';
    Filtered:=False;
    Active := True;
    First;
  end;
  cbKabkot.Clear;
  i:=0;

  if (skodekab<>'00') then
    skabkot:=skodekab;
  if (skodekec<>'') then
    skec:=skodekec;

  while (not ZTable1.Eof) do
  begin
    cbKabkot.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    if (skabkot=ZTable1.FieldByName('KODE').AsString) then
      idx:=i;
    ZTable1.Next;
    Inc(i);
  end;
  if (skodekab<>'00') then begin
   cbKabkot.Enabled:=false;
   skabkot:=skodekab;
  end;
  //ShowMessage(ikabkot);
  cbKabkot.ItemIndex:=idx;
  //KEC
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kecamatan';
    Filter := 'KODE_KABKOT='+QuotedStr(skabkot);
    Filtered:=True;
    Active := True;
    First;
  end;
  cbKec.Clear;
  i:=0;
  while (not ZTable1.Eof) do
  begin
    cbKec.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    if (skec=ZTable1.FieldByName('KODE_KECAMATAN').AsString) then
      idx:=i;
    ZTable1.Next;
    Inc(i);
  end;
  cbKec.ItemIndex:=idx;
  if (skodekec<>'') then begin
   cbkec.Enabled:=false;
   skec:=skodekec;
  end;

  //DESA
  with ZTable1 do
  begin
    Active := False;
    TableName := 'desa';
    Filter := 'KODE_KECAMATAN='+QuotedStr(skec);
    Filtered:=True;
    Active := True;
    First;
  end;
  cbDesa.Clear;
  i:=0;
  while (not ZTable1.Eof) do
  begin
    cbDesa.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    if (sdesa=ZTable1.FieldByName('KODE_DESA').AsString) then
      idx:=i;
    ZTable1.Next;
    Inc(i);
  end;
  cbDesa.ItemIndex:=idx;
  //TPS
  with ZTable1 do
  begin
    Active := False;
    TableName := 'kabkot';
    Filtered:=False;
    Active := True;
    First;
  end;
  cbT1.Clear;
  cbT2.Clear;
  cbT3.Clear;
  cbT4.Clear;
  i:=0;
  idx:=-1;
  while (not ZTable1.Eof) do
  begin
    cbT1.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
    if (skodekab=ZTable1.FieldByName('KODE').AsString) then
      idx:=i;
    ZTable1.Next;
    Inc(i);
  end;
  if (skodekab<>'00') then begin
   cbT1.Enabled:=false;
   skabkot2:=skodekab;
  end;
  cbT1.ItemIndex:=idx;
    //KEC
    with ZTable1 do
    begin
      Active := False;
      TableName := 'kecamatan';
      Filter := 'KODE_KABKOT='+QuotedStr(skabkot);
      Filtered:=True;
      Active := True;
      First;
    end;
    cbT2.Clear;
    i:=0;
    idx:=-1;
    while (not ZTable1.Eof) do
    begin
      cbT2.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
      if(skodekec=ZTable1.FieldByName('KODE_KECAMATAN').AsString)then
        idx:=i;
      ZTable1.Next;
      Inc(i);
    end;
    cbT2.ItemIndex:=idx;
    if (skodekec<>'') then begin
      cbT2.Enabled:=false;
      sKec2:=skodekec;
      with ZTable1 do
      begin
        Active := False;
        TableName := 'desa';
        Filter := 'KODE_KECAMATAN='+QuotedStr(skec);
        Filtered:=True;
        Active := True;
        First;
        while (not ZTable1.Eof) do
        begin
          cbT3.Items.Add(ZTable1.FieldByName('TAMPIL').AsString);
          ZTable1.Next;
        end;
      end;

    end;

    //DESA
    idtps:='0';
end;

function TForm_Ftambah.ketTPS(id:String):String;
begin
  with ZTable1 do begin
    active:=false;
    tablename:='daftar_tps';
    filter:='ID_TPS='+id;
    filtered:=true;
    active:=true;
    First;
    Result:=FieldByName('NAMA').AsString;
  end;
end;

function TForm_Ftambah.ketS1(id:integer):String;
begin
  case id of
    0 : Result:='DPS';
    1 : Result:='DPS Baru';
    2 : Result:='DPS Edit';
    else
      Result:='';
    end;
end;

function TForm_Ftambah.ketS2(id:integer):String;
begin
  case id of
    1 : Result:='Meninggal Dunia';
    2 : Result:='Data Fiktif';
    3 : Result:='TNI/POLRI';
    4 : Result:='Pindah Alamat';
    5 : Result:='HAPUS';
    else
      Result:='';
    end;
end;

function TForm_Ftambah.ketGanda(id:integer):String;
begin
  if id=0 then
    Result:='TIDAK'
  else
    Result:='IYA';
end;

function TForm_Ftambah.ketSP(id:integer):String;
begin
  case id of
    1 : Result:='Biasa';
    2 : Result:='Cacat Mental/Jiwa';
    3 : Result:='Dicabut Hak Pilih';
    4 : Result:='Pidana 5 Tahun';
    5 : Result:='Tidak Punya Hak Pilih';
    6 : Result:='Belum Punya Hak Pilih';
    else
      Result:='';
    end;
end;

function TForm_Ftambah.ketAP(id:integer):String;
begin
  case id of
    1 : Result:='Meninggal Dunia';
    2 : Result:='Pindah domisili';
    3 : Result:='Tidak dikenal';
    4 : Result:='Salah status pemilih';
    5 : Result:='Salah jenis kelamin';
    6 : Result:='Salah nama';
    7 : Result:='Salah alamat';
    8 : Result:='Terdaftar ganda';
    9 : Result:='Lainnya';
    10 : Result:='Dicabut Hak Pilih';
    11 : Result:='Bukan Data Gand';
    12 : Result:='Hapus Tanda';
    13 : Result:='Hapus Pemilih';
    else
      Result:='';
    end;
end;

function TForm_Ftambah.ketCa(id:integer):String;
begin
  case id of
    1 : Result:='Cacat Fisik';
    2 : Result:='Cacat Netra/buta';
    3 : Result:='Cacat rungu wicara';
    4 : Result:='Cacat mental jiwa';
    5 : Result:='Cacat fisik/mental';
    6 : Result:='Cacat lainnya';
    else
      Result:='';
    end;
end;

function TForm_Ftambah.ketPend(id:integer):String;
begin
  case id of
    1 : Result:='Tidak/Belum Sekolah';
    3 : Result:='Tidak Tamat SD';
    4 : Result:='SLTP';
    5 : Result:='SLTA';
    6 : Result:='DI/II';
    7 : Result:='DIII';
    8 : Result:='S1/D4';
    9 : Result:='S2';
    10 : Result:='S3';
    2 : Result:='Tamat SD';
    else
      Result:='';
  end;
end;

function TForm_Ftambah.ketSR(id:integer):String;
begin
  case id of
  1 : Result:='Kepala RT';
  2 : Result:='Istri/Suami';
  3 : Result:='Anak';
  4 : Result:='Menantu';
  5 : Result:='Cucu';
  6 : Result:='Orang Tua';
  7 : Result:='Mertua';
  8 : Result:='Famili Lain';
  9 : Result:='Pembantu';
  10 : Result:='Lainnya';
  else
    Result:='';
  end;
end;

function TForm_Ftambah.ketPek(id:integer):String;
begin
  case id of
    1 : Result:='Pelajar';
    2 : Result:='Pengurus RT';
    3 : Result:='Pensiunan';
    4 : Result:='Blm/tdk bekerja';
    5 : Result:='Petani';
    6 : Result:='Peternak';
    7 : Result:='Nelayan';
    8 : Result:='Industri';
    9 : Result:='Kontruksi';
    10 : Result:='Perdagangan';
    11 : Result:='Transportasi';
    12 : Result:='PNS';
    13 : Result:='TNI';
    14 : Result:='Polri';
    15 : Result:='Jasa lainnya';
    else
      Result:='';
  end;
end;

function TForm_Ftambah.ketWN(id:integer):String;
begin
  case id of
    1 : Result:='WNI';
    2 : Result:='WNA';
    else
      Result:=''
  end;
end;

function TForm_Ftambah.getKec(kode:String):String;
var
  I:integer;
begin
  for I := 0 to Length(bKec) - 1 do begin
    if (bKec[i].KODE=kode) then
      break;
  end;
    Result:=bKec[i].NAMA;
end;

function TForm_Ftambah.getKabkot(kode:String):String;
var
  I:integer;
begin
  for I := 0 to Length(bKabkot) - 1 do begin
    if (bKabkot[i].KODE=kode) then
      break;
  end;
    Result:=bKabkot[i].NAMA;
end;

function TForm_Ftambah.getIdsimpan(tabel:String):String;
var
  I:integer;
  res:String;
begin
  res:='';
  for I := 0 to Length(bPenyimpan) - 1 do begin
    if (bPenyimpan[i].NAMA=tabel) then begin
      res:=bPenyimpan[i].ID;
      break;
    end;
  end;
    Result:=res;
end;

function TForm_Ftambah.getSimpan(id:String):String;
var
  I:integer;
  res:String;
begin
  res:='';
  for I := 0 to Length(bPenyimpan) - 1 do begin
    if (bPenyimpan[i].ID=id) then begin
      res:=bPenyimpan[i].NAMA;
      break;
    end;
  end;
    Result:=res;
end;

function TForm_Ftambah.getTabel(id:String):String;
begin
  Result:=Copy(id,1,16);
end;

function TForm_Ftambah.getIduser(id:String):String;
begin
  Result:=Copy(id,17,(Length(id)-16));
end;

function TForm_Ftambah.getDesa(kode:String):String;
var
  I:integer;
begin
  for I := 0 to Length(bDesa) - 1 do begin
    if (bDesa[i].KODE=kode) then
      break;
  end;
    Result:=bDesa[i].NAMA;
end;

procedure TForm_Ftambah.AutoSizeCol(Grid: TStringGrid; Column: integer);
var
  i, W, WMax: integer;
begin
  WMax := 0;
  for i := 0 to (Grid.RowCount - 1) do begin
    W := Grid.Canvas.TextWidth(Grid.Cells[Column, i]);
    if W > WMax then
      WMax := W;
  end;
  Grid.ColWidths[Column] := WMax + 5;
end;

procedure TForm_Ftambah.Timer1Timer(Sender: TObject);
begin
  if(Label2.Visible = true) then
    Label2.Visible := false
  else
    Label2.Visible := true;
end;

procedure TForm_Ftambah.txtTahunKeyPress(Sender: TObject; var Key: Char);
begin
  //
end;

procedure TForm_Ftambah.txtTahunKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = VK_RETURN then begin
  end;
end;

procedure TForm_Ftambah.txtTahunChange(Sender: TObject);
var
  tt:String;
begin
  
end;

procedure TForm_Ftambah.txtTahunClick(Sender: TObject);
begin
  txtTahun.Text:='';
end;

procedure TForm_Ftambah.txtTahunExit(Sender: TObject);
var
  tt:String;
begin
  if (txtTahun.Text<>'') then begin
      tt:=txtTahun.text;
      if (length(txtTahun.Text)=2) then
        txtTahun.text:= '19'+tt
      else if (length(txtTahun.Text)=1) then
        txtTahun.text:= '190'+tt;
    end;
end;

end.
